from django.template import Library
from django.conf import settings

import pytz

from blog.utils import localtime_from_utc, utc_from_localtime

register = Library()

def localdate(datetime, option):
    if not datetime:
        'None'
    datetime = localtime_from_utc(datetime)
    represent_date = ''
    if option == 'y':
        datetime.strftime("%Y")
    elif option == 'm':
        datetime.strftime("%b")
    elif option == 'd':
        datetime.strftime("%d")
    else:
        datetime.strftime("%d/ %b/ %Y")
    return represent_date

def localyear(datetime):
    if not datetime:
        'None'
    datetime = localtime_from_utc(datetime)
    return datetime.strftime("%Y")

def localmonthday(datetime):
    if not datetime:
        'None'
    datetime = localtime_from_utc(datetime)
    return datetime.strftime("%d %b")

def localday(datetime):
    if not datetime:
        'None'
    datetime = localtime_from_utc(datetime)
    return datetime.strftime("%d")

def localdate_link(datetime):
    datetime = localtime_from_utc(datetime)
    return datetime.strftime("%Y/%m/%d")

def localtime(datetime):
    datetime = localtime_from_utc(datetime)
    return datetime.strftime("%H:%M:%S")

register.filter("localyear", localyear)
register.filter("localmonthday", localmonthday)
register.filter("localday", localday)
register.filter("localdate_link", localdate_link)
register.filter("localtime", localtime)